﻿@model PhoneBilling.Models.ExtensionMgtModel

<script type="text/javascript">
    function motion(groupID) {
        
        var str = "";
        $(".account").each(function () {
            if ($(this).attr("checked") == "checked") {
                if (str == "")
                    str += $(this).attr("id");
                else
                    str += "!" + $(this).attr("id");
            }
        });
        
        window.location.href = "/Manage/ExtensionMotion?selectedItem=" + str + "&groupID=" + groupID;
    }
    function c1() {
        if ($(".c1").attr("checked") == "checked") {
            $(".account").attr("checked", "checked");
        }
        else {
            $(".account").removeAttr("checked");
        }
    }
    function del(id, name) {
        var r = confirm("确认删除分机：" + name + "吗？");
        if (r == true) {
            window.location.href = "/Manage/ExtensionDelete?groupID=" + id+"&id="+name;
        }
        return false;
    }
    function delb(id) {
        var str = "";
        var phone = "";
        $(".account").each(function () {
            if ($(this).attr("checked") == "checked") {
                phone += "\r\n" + $(this).attr("id");
                if (str == "") {
                    str += $(this).attr("id");
                }
                else {
                    str += "!" + $(this).attr("id");
                }
            }
        });
        if (phone == "")
            return;

        var r = confirm("确认删除下列分机吗？" + phone);
        if (r == true) {
            window.location.href = "/Manage/ExtensionBatchDelete?phone=" + str + "&groupID=" + id;
        }
        return false;
    }
    function change() {
        var grade = $(".grade").val();

        if (grade != "") {
            $(".ext").hide();
            $(".E-" + grade).show();
            $(".listCounts").text($(".E-" + grade).length);
        }
        else {
            $(".ext").show();
            $(".listCounts").text($(".ext").length);
        }
    }
</script>
<div class="input-text">
             @Html.LabelFor(m => m.Group)
             @if (Model.Group != null)
             {
             @Html.DisplayFor(m => m.Group)
             }
             else
             {
                 <label>(未分组分机)</label>
             }
        </div>
@if (Model.Message != null)
{<h2>@Model.Message</h2>}
@if (Model.Group != null)
{
    <p id="btn-create" class="box"><input  type="checkbox" class="c1" onclick="c1()" checked="checked" /><label>全选</label>
    <span>    </span>@Html.ActionLink("新增分机", "ExtensionEdit", new { groupID = Model.GroupID })
    @if(!Model.IsDept){<span>    </span>@Html.ActionLink("排序", "ExtensionSort", new { id = Model.GroupID })}
    <span>    </span><a href=# onclick="delb('@Model.GroupID')"><span>删除</span></a>
    <span>    </span><a href=# onclick="motion('@Model.GroupID')"><span>迁移</span></a></p>
}
else
{
    <p id="btn-create" class="box"><input  type="checkbox" class="c1" onclick="c1()" checked="checked" /><label>全选</label>
    <span>    </span><a href=# onclick="delb('@Model.GroupID')"><span>删除</span></a>
    <span>    </span><a href=# onclick="motion('@Model.GroupID')"><span>迁移</span></a></p>
}

@Html.HiddenFor(m => m.SelectItem, new { id = "SelectItem" })
<p id="btn-create" class="box"><label>分机数：</label><label class="listCounts">@Model.ExtensionList.Count</label><span>    </span>@Html.LabelFor(m => m.收费等级) @Html.DropDownListFor(m => m.收费等级, new SelectList(Model.GradeList, "ID", "Name"), new { style = "input-text", onchange = "change()", @class = "grade" })</p>
@{
    var grid = new WebGrid(source: Model.ExtensionList, canPage: false);
}
<table>
    <tr>
        <th>选择</th>
        <th>分机号码</th>
        <th>分组</th>
        <th>用户名</th>
        <th>收费等级</th>
        <th>费率</th>
        <th>收费话类</th>
        <th></th>
        <th></th>
        <th></th>
    </tr>
    @{
        foreach (var detail in Model.ExtensionList)
        {
        <tr class="ext E-@detail.收费等级">
            <td>@Html.CheckBox("选择", true, new { id = @detail.分机号码, @class = "account" })</td>
            <td>@detail.分机号码</td>
            <td>@detail.分组</td>
            <td>@detail.用户名</td>
            <td>@detail.收费等级</td>
            <td>@detail.费率</td>
            <td>@detail.收费话类</td>
            <td>@Html.ActionLink("修改", "ExtensionEdit", new { id = detail.分机号码, groupID = Model.GroupID })</td>
            <td>@Html.ActionLink("迁移", "ExtensionMotion", new { selectedItem = detail.分机号码, groupID = Model.GroupID })</td>
            <td>@Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", Model.GroupID, detail.分机号码))</td>
        </tr>
        }
    }
</table>

@*
@grid.GetHtml(
    alternatingRowStyle: "bg",
    columns: grid.Columns
    (
        grid.Column(format: (item) => Html.CheckBox("选择", true, new { id = item.分机号码, @class = "account" })),
        grid.Column("分机号码", "分机号码"),
        grid.Column("用户名", "用户名"),
        grid.Column("地址", "地址"),
        grid.Column("收费等级", "收费等级"),
        grid.Column("费率", "费率"),
        grid.Column("收费话类", "收费话类"),
        grid.Column("月杂费", "月杂费"),
        grid.Column("安装日期", "安装日期"),
        grid.Column(format: (item) => Html.ActionLink("修改", "ExtensionEdit", new { id = item.分机号码, groupID = Model.GroupID })),
        grid.Column(format: (item) => Html.ActionLink("迁移", "ExtensionMotion", new { selectedItem = item.分机号码})),
        grid.Column(format: (item) => Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", Model.GroupID , item.分机号码)))
    )
)*@

